package com.yn.club.subject.application.controller;



import com.yn.club.subject.domain.entity.SubjectJudgeDO;
import com.yn.club.subject.application.dto.SubjectJudgeDTO;
import com.yn.club.subject.domain.service.SubjectJudgeDomainService;
import org.springframework.web.bind.annotation.*;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.validation.annotation.Validated;
import javax.validation.constraints.NotEmpty;
import java.io.Serializable;
import java.util.List;
import com.yn.club.common.util.R;
import com.yn.club.common.util.PageReq;
import com.yn.club.common.util.PageResp;
import com.yn.club.subject.application.convert.SubjectJudgeApplicationConverter;
import com.yn.club.subject.application.request.SubjectJudgeQueryRequest;
import com.yn.club.subject.application.request.SubjectJudgeSaveRequest;

/**
 * 判断题(SubjectJudge)表控制层
 *
 * @author YN
 * @since 2025-01-21 17:40:47
 */
@Slf4j
@RequiredArgsConstructor
@Validated
@RestController
@RequestMapping("subjectJudge")
public class SubjectJudgeController {
    /**
     * 服务对象
     */
    private final SubjectJudgeDomainService subjectJudgeDomainService;
    private final SubjectJudgeApplicationConverter subjectJudgeApplicationConverter;

    /**
     * 分页查询数据
     *
     * @param pageReq 分页参数
     * @param query   查询条件
     * @return 所有数据
     */
    @GetMapping
    public R<PageResp<SubjectJudgeDTO>> queryPage(PageReq pageReq, SubjectJudgeQueryRequest query) {
        SubjectJudgeDO subjectJudgeDO = subjectJudgeApplicationConverter.convertQueryRequestToDo(query);
        PageResp<SubjectJudgeDO> page = subjectJudgeDomainService.page(pageReq, subjectJudgeDO);
        
        List<SubjectJudgeDTO> subjectJudgeDTOS = subjectJudgeApplicationConverter.convertDoToDto(page.getList());
        return R.ok(PageResp.of(page,subjectJudgeDTOS));
    }

    /**
     * 通过主键查询单条数据
     *
     * @param id 主键
     * @return 单条数据
     */
    @GetMapping("{id}")
    public R<SubjectJudgeDTO> selectOne(@PathVariable Serializable id) {
    SubjectJudgeDTO subjectJudgeDTO = subjectJudgeApplicationConverter.convertDoToDto(
      this.subjectJudgeDomainService.getById(id));
     
    return R.ok(subjectJudgeDTO);
    }

    /**
     * 新增数据
     *
     * @param subjectJudge 实体对象
     * @return 受影响条数
     */
    @PostMapping
    public R<Boolean> insert(@RequestBody SubjectJudgeSaveRequest subjectJudge) {
       SubjectJudgeDO subjectJudgeDO = subjectJudgeApplicationConverter.convertSaveRequestToDo(subjectJudge);
        return R.ok(this.subjectJudgeDomainService.insert(subjectJudgeDO));
    }

    /**
     * 修改数据
     *
     * @param subjectJudge 实体对象
     * @return 受影响条数
     */
    @PutMapping
    public R<Boolean> update(@RequestBody SubjectJudgeSaveRequest subjectJudge) {
        SubjectJudgeDO subjectJudgeDO = subjectJudgeApplicationConverter.convertSaveRequestToDo(subjectJudge);
        return R.ok(this.subjectJudgeDomainService.updateById(subjectJudgeDO));
    }

    /**
     * 删除数据
     *
     * @param ids 主键结合
     * @return 受影响条数
     */
    @DeleteMapping
    public R<Boolean> delete(@RequestBody @NotEmpty List<Integer> ids) {
        return R.ok(this.subjectJudgeDomainService.delete(ids));
    }
}

